package com.wmm.job4;

import java.util.List;
import java.util.Scanner;

public class ListStudent {

    public static List<Student> list;

    public void addStudent(String id,String name,int age){
        Student st = new Student(id,name,age);
        list.add(st);
    }

    public void showStudent(){
        if (list.size()<=0){
            System.out.println("没有任何学生信息。");
        }
        for(Student st : list){
            System.out.println("学生的ID号："+st.getId()+ "，姓名：" +st.getName()+ "，年龄：" +st.getAge());
        }
    }

    public void findById(String id){
        for(Student st : list) {
            if (st.getId().equals(id)) {
                System.out.println("学生的ID号：" + st.getId() + "，姓名：" + st.getName() + "，年龄：" + st.getAge());
                return;
            }
        }
        System.out.println("没有查询到此学生的信息");
    }

    public void findByName(String name){
        for(Student st : list) {
            if (st.getId().equals(name)){
                System.out.println("学生的ID号："+st.getId()+ "，姓名：" +st.getName()+ "，年龄：" +st.getAge());
                return;
            }
        }
        System.out.println("没有查询到此学生的信息");
    }

    public void deleteStudent(String id){
        for(int i = 0;i<list.size();i++) {
            if (list.get(i).getId().equals(id)){
               list.remove(i);
               System.out.println("删除成功!!!");
               return;
            }
        }
        System.out.println("没有查询到此学生的信息");
    }

    public void updateStudent(String id){
        for(int i = 0;i<list.size();i++) {
            if (id.equals(((Student)list.get(i)).getId())){
                Scanner sc = new Scanner(System.in);
                System.out.println("输入更改的学生姓名：");
                String name = sc.next();

                System.out.println("输入更改的学生年龄：");
                int age = sc.nextInt();
                Student st = new Student(((Student)list.get(i)).getId(),name,age);
                list.set(i,st);
            }
        }
    }
}
